#include "StdAfx.h"


//Written by Arseni Natapov, 1/5/2011;
//parametrized constructor
//all params default to 0
Rotator::Rotator(real yaw, real pitch, real roll)
{
	this->yaw=yaw;
	this->pitch=pitch;
	this->roll=roll;
}
Rotator::~Rotator(void)
{
}
void Rotator::Rotate(Vec3 &v)
{
	Quat q=*this;
	q.rotate(v);
}
//reset all to 0
void Rotator::Reset()
{
	yaw=pitch=roll=0;
}
Rotator Rotator::operator -()
{
	return Rotator(-yaw,-pitch-roll);
}
//operators
//casting operators
Rotator::operator Vec3()
{
	Vec3 v=Vec3(1,0,0);
	Quat q=*this;
	q.rotate(v);
	return v;
}
Rotator::operator Quat()
{
	Quat yawq, pitchq, rollq, finalq;
	real factor=PI/180;
	yawq.fromAngleAxisFast(yaw*factor, Vec3(0, 1, 0));
	pitchq.fromAngleAxisFast(pitch*factor, Vec3(1, 0, 0));
	rollq.fromAngleAxisFast(roll*factor, Vec3(0, 0, 1));
	finalq=yawq*pitchq*rollq;
	return finalq;
}
//returns a rotational matrix
Rotator::operator Mat33()
{
	Mat33 mat;
	Quat q=*this;
	mat=q;
	return mat;
}
//assignment operator
Rotator Rotator::operator =(Rotator &rot)
{
	yaw=rot.yaw;
	pitch=rot.pitch;
	roll=rot.roll;
	return *this;
}
//comparison operators
bool Rotator::operator ==(Rotator &rot)
{
	return yaw==rot.yaw
		&&pitch==rot.pitch
		&&roll==rot.roll;
}
bool Rotator::operator !=(Rotator &rot)
{
	return !(*this==rot);
}
//arithmetic operators
Rotator Rotator::operator +(Rotator &rot)
{
	Rotator tempRot;
	tempRot.yaw=yaw+rot.yaw;
	tempRot.pitch=pitch+rot.pitch;
	tempRot.roll=roll+rot.roll;
	return tempRot;
}
void Rotator::operator +=(Rotator &rot)
{
	yaw+=rot.yaw;
	pitch+=rot.pitch;
	roll+=rot.roll;
}
Rotator Rotator::operator -(Rotator &rot)
{
	Rotator tempRot;
	tempRot.yaw=yaw-rot.yaw;
	tempRot.pitch=pitch-rot.pitch;
	tempRot.roll=roll-rot.roll;
	return tempRot;
}
void Rotator::operator -=(Rotator &rot)
{
	yaw-=rot.yaw;
	pitch-=rot.pitch;
	roll-=rot.roll;
}
